package com.qf.utils;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.qf.utils
 * @Description:
 * @Date 2022/7/1 17:04
 */
public class EsClient {

    /**
     * 获取和ES服务器的连接
     */
    public static RestHighLevelClient getClient(){
        //1.创建和服务器的连接
        HttpHost httpHost = new HttpHost("192.168.200.129",9200);
        //2.创建restClient对象
        RestClientBuilder builder = RestClient.builder(httpHost);
        //创建返回可以使用的连接对象
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
        return restHighLevelClient;
    }
}
